package com.anXin.article.service.impl;

import com.anXin.article.mapper.ReplyChildMapper;
import com.anXin.article.mapper.ReplyMapper;
import com.anXin.article.mapper.SensitiveMapper;
import com.anXin.article.service.ReplyService;
import com.anXin.article.service.SensitiveService;
import com.anXin.model.article.pojos.Reply;
import com.anXin.model.article.pojos.ReplyChild;
import com.anXin.model.article.pojos.Sensitive;
import com.anXin.model.common.dtos.ResponseResult;
import com.anXin.model.common.dtos.article.ServiceCode;
import com.anXin.model.common.dtos.article.ServiceException;
import com.anXin.model.common.enums.AppHttpCodeEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class SensitiveServiceImpl extends ServiceImpl<SensitiveMapper, Sensitive> implements SensitiveService {


    @Override
    public ResponseResult add(String sensitives) {
        Sensitive sensitive = new Sensitive();
        sensitive.setSensitives(sensitives);
        boolean save = save(sensitive);
        if (save)return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

    @Override
    public ResponseResult updatesensitive(Sensitive sensitive) {
        boolean update = updateById(sensitive);
        if (update)return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

    @Override
    public ResponseResult sensitiveList() {
        return ResponseResult.okResult(query().list());
    }

    @Override
    public ResponseResult batchDelete(Long[] ids) {
        boolean removeByIds = removeByIds(Arrays.stream(ids).collect(Collectors.toList()));
        if (removeByIds)return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }
}
